package com.msunsoft.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

/**
 * 和Web层相关的实用工具类
 */
public class WebUtils {

    /**
     * 将请求参数封装为Map
     * 
     * @param request
     * @return
     */
    public static Map<String, String> getPraramsAsMap(HttpServletRequest request){
        Map<String, String> requestParameterMap = new HashMap<String, String> ();
        Map map = request.getParameterMap ();
        Iterator keyIterator = (Iterator) map.keySet ().iterator ();
        while (keyIterator.hasNext ()) {
            String key = (String) keyIterator.next ();
            String value = ((String[]) (map.get (key)))[0];
            if (value == null || "null".equalsIgnoreCase (value)) {
                value = "";
            }
            requestParameterMap.put (key, value);
        }
        return requestParameterMap;
    }

}
